/**
 * 
 */
package cn.jy.erp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;

import cn.jy.erp.domain.mobile.Partsmade;
import cn.jy.erp.domain.mobile.PartsmadeDetail;
import cn.jy.erp.domain.mobile.Person;
import cn.jy.erp.mapper.mobile.PartsmadeDetailMapper;
import cn.jy.erp.mapper.mobile.PartsmadeMapper;
import cn.jy.erp.service.MobilePartsmadeService;

/**
 * @author 刘中斐
 *@date 2018年8月28日 下午1:36:46 
 */
@Service
public class MobilePartsmadeServiceImpl implements MobilePartsmadeService{

	@Autowired
	private PartsmadeMapper partsmadeMapper;
	@Autowired
	private PartsmadeDetailMapper partsmadeDetailMapper;
	@Override
	public List<Partsmade> getByIdList() {

		return partsmadeMapper.getByIdList();
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void savePartsmadeDetail(PartsmadeDetail partsmadeDetail) throws Exception {
		System.out.println(partsmadeDetail.getTid());
		List<PartsmadeDetail> byTidData = partsmadeDetailMapper.getByTidData(partsmadeDetail.getTid());	

		if (byTidData.size()>0) {
			for (PartsmadeDetail partsmadeDetail2 : byTidData) {
				
					partsmadeDetail.setDid(partsmadeDetail2.getDid());
					partsmadeDetailMapper.updateByPrimaryKeySelective(partsmadeDetail);
				}
			
		}else {
			partsmadeDetailMapper.insertSelective(partsmadeDetail);
			
		}
		

	}


	@Override
	public List<PartsmadeDetail> getByTidData(String tid) {

		return partsmadeDetailMapper.getByTidData(tid);
	}

	@Override
	public List<Person> getLogin(String personName) {

		return partsmadeMapper.getByLogin(personName);
	}

	@Override
	public List<String> getByLjMB(String persontype) {

		return partsmadeDetailMapper.getByLjMB(persontype);
	}

}
